/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fir;

/**
 *
 * @author zhangyucen
 */
public class Chess {

    int xAccess[];
    int yAccess[];
    int current;
    int pos;    //used in loading game
    int point[][];
    boolean tableplayer1[][][];
    boolean tableplayer2[][][];

    public Chess() {
        xAccess = new int[225];
        yAccess = new int[225];
        point = new int[15][15];
        tableplayer1 = new boolean[572][15][15];    //572 ways to win
        tableplayer2 = new boolean[572][15][15];
        init();
    }

    void init() {
        current = 0;
        pos = 0;

        int i, j, k, count = 0;
        for (i = 0; i < 225; i++) {
            xAccess[i] = 0;
            yAccess[i] = 0;
        }
        for (i = 0; i < 15; i++) {
            for (j = 0; j < 15; j++) {
                point[i][j] = 0;    //set board as empty
            }
        }
        //水平方向获胜位置
        for (i = 0; i < 15; i++) {
            for (j = 0; j < 11; j++) {
                for (k = 0; k < 5; k++) {
                    tableplayer1[count][i][j+k] = true;
                    tableplayer2[count][i][j+k] = true;
                }
                count++;
            }
        }
        //垂直方向获胜位置
        for (i = 0; i < 11; i++) {
            for (j = 0; j < 15; j++) {
                for (k = 0; k < 5; k++) {
                    tableplayer1[count][i+k][j] = true;
                    tableplayer2[count][i+k][j] = true;
                }
                count++;
            }
        }
        //正对角线方向获胜位置
        for (i = 0; i < 11; i++) {
            for (j = 0; j < 11; j++) {
                for (k = 0; k < 5; k++) {
                    tableplayer1[count][i+k][j+k] = true;
                    tableplayer2[count][i+k][j+k] = true;
                }
                count++;
            }
        }
        //反对角线方向获胜位置
        for (i = 0; i < 11; i++) {
            for (j = 14; j >= 4; j--) {
                for (k = 0; k < 5; k++) {
                    tableplayer1[count][i+k][j-k] = true;
                    tableplayer2[count][i+k][j-k] = true;
                }
                count++;
            }
        }
    }

    void modify(int x, int y, int state) {
        point[x][y] = state;
        xAccess[current] = x;
        yAccess[current] = y;
        current++;
    }

    void regret() {
        if(current > 0) {
            point[xAccess[current-1]][yAccess[current-1]] = 0;
            current--;
            point[xAccess[current-1]][yAccess[current-1]] = 0;
            current--;
        }
    }
}
